package com.cincc.cinccimdemo.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.cincc.im.core.IMSipPhoneCtrl;
import com.cincc.im.model.dbmodel.FriendInfo;
import com.cincc.im.util.ImManager;

import java.util.List;

public class ContactViewModel extends ViewModel {
    private MutableLiveData<List<FriendInfo>> contactListLiveData;


    public MutableLiveData<List<FriendInfo>> contactListLiveData() {
        if (contactListLiveData == null) {
            contactListLiveData = new MutableLiveData<>();
        }
        ImManager.getInstance().getWorkHandler().post(() -> {
            List<FriendInfo> friendInfos = IMSipPhoneCtrl.getInstance().getFriendListSync();
            contactListLiveData.postValue(friendInfos);
        });
        return contactListLiveData;
    }

    public void setContact() {
        ImManager.getInstance().getWorkHandler().post(() -> {
            List<FriendInfo> friendInfos = IMSipPhoneCtrl.getInstance().getFriendListSync();
            contactListLiveData.postValue(friendInfos);
        });
    }
}
